class Queue {
  constructor() {
    this.arr = [];
  }

  isEmpty() {
    return this.arr.length === 0;
  }
  size() {
    return this.arr.length;
  }
  peek() {
    return this.arr[0];
  }

  enqueue(data) {
    this.arr.push(data);
  }

  dequeue() {
    return this.arr.shift();
  }
}

var MyStack = function () {
  this.queue = new Queue();
};

/**
 * @param {number} x
 * @return {void}
 */
MyStack.prototype.push = function (x) {
  this.queue.enqueue(x);
};

/**
 * @return {number}
 */
MyStack.prototype.pop = function () {
  var tempQueue = new Queue();
  while (this.queue.size() > 1) {
    tempQueue.enqueue(this.queue.dequeue());
  }
  var value = this.queue.dequeue();
  this.queue = tempQueue;
  return value;
};

/**
 * @return {number}
 */
MyStack.prototype.top = function () {
  var value = this.pop();
  this.push(value);
  return value;
};

/**
 * @return {boolean}
 */
MyStack.prototype.empty = function () {
  return this.queue.isEmpty();
};

var myStack = new MyStack();
myStack.enqueue(1);
myStack.enqueue(2);
console.log(myStack.top()); // 返回 2
console.log(myStack.dequeue()); // 返回 2
console.log(myStack.empty()); // 返回 False
